<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>模块管理</title>
  <link href="../../css/style.css" rel="stylesheet" type="text/css" />
  <script src="../../js/api.js"></script>
  <script src="../../js/axios.js"></script>
  <script src="../../js/jquery-3.3.1.js"></script>
  <script src="../../js/commons/messageInfo.js"></script>
</head>

<body>
  <div class="place"> <span>位置：</span>
    <ul class="placeul">
      <li><a href="../users/userList.html">系统管理</a></li>
      <li><a href="moduleList.html">模块管理</a></li>
      <li><a href="#">修改</a></li>
    </ul>
  </div>
  <div class="formbody">
    <div class="formtitle"><span>模块信息</span></div>
    <ul class="forminfo">
      <li>
        <label>模块名称</label>
        <input id="rname" type="text" value="用户管理" class="dfinput" />
        <i id="ri" style="color: red;"></i>
      </li>
      <li>
        <label>父模块</label>
        <select id="select" class="dfselect">
        </select>
      </li>
      <li>
        <label>URL</label>
        <input id="url" type="text" class="dfinput" />
        <i id="ui" style="color: red;"></i
      </li>
      <li>
        <label>&nbsp;</label>
        <input onclick="save()" type="button" class="btn" value="确认保存" />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input name="" type="button" class="btn" value="返回" onclick="location.href='moduleList.html'" />
      </li>
    </ul>
  </div>

  <script type="text/javascript">
    let obj = {}
    const arr = decodeURI(location.href.split('?')[1]).split('&')
    for (let i = 0; i < arr.length; i++) {
      const e = arr[i];
      const a = e.split('=')
      if (a[0] === 'id') {
        obj.id = a[1]
      } else if (a[0] === 'rname') {
        obj.rname = a[1]
        $('#rname').val(a[1])
      } else if (a[0] === 'parent') {
        obj.parent = a[1]
      } else {
        obj.url = a[1]
        $('#url').val(a[1])
      }
    }
    axiosRequest1('get', '/module/getParent').then((result) => {
      const { code, message, data } = result.data
      if (code === 200) {
        let s = '<option value=0>请选择父模块</option>'
        data.forEach(e => {
          s += `<option value='${e.moduleId}' >${e.moduleRName}</option>`
        });
        $('#select').html(s)
        $('#select').val(obj.parent)
      } else showMessage(message, 2000)
    }).catch((err) => {
      console.log(err);
    });

    appendMsgBox()

    function save(){
      let moduleRName=$('#rname').val().trim()
      if(moduleRName===''){
        $('#ri').text('请填写模块名称')
        return
      }
      let moduleMUrl=$('#url').val().trim()
      if(moduleMUrl==''){
        $('#ui').text('请填写模块地址')
        return
      }
      let modulePid=$('#select').val()
      if(moduleRName===obj.rname && modulePid==obj.parent && moduleMUrl===obj.url){
        showMessage('请对模块作出修改',2000)
        return 
      }
      axiosRequest1('post','/module/update',
      {moduleId:obj.id,moduleRName,moduleMUrl,modulePid}).then((res) => {
        showMessage(res.data.message,2000)
      }).catch((err) => {
        console.log(err);
      });
    }

  </script>

</body>

</html>